package com.nl.controller.web.controller;

import com.nl.controller.web.service.ExternalMessageTempService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

/**
 * @desc 外部短信模板交互接口
 * @return null
 * @author ll
 * @date 2020/12/24 9:30
 */
@Slf4j
@RestController
@RequestMapping("externalMessageTemp")
public class ExternalMessageTempController {
    //鉴权盐值
    public static String KEY = "emtyjpt";

    @Autowired
    SmsPxQxjController smsPxQxjController;

    @Autowired
    ExternalMessageTempService externalMessageTempService;

    //外部短信模板同步接口
    @RequestMapping(value = "messageDetailSyn")
    public Map<String,Object> messageDetailSyn(HttpServletRequest request){
        InputStream in;
        String reqJson="";
        String timeStamp = "";
        Map<String, Object> map = new HashMap<>();
        try {
            in = request.getInputStream();
            reqJson = IOUtils.toString(in, "utf-8");
            log.info("sendTaskDetailSyn:"+reqJson);
        } catch (IOException e) {
            e.printStackTrace();
            log.error(e.toString());
        }

        //boolean authResult = smsPxQxjController.getAuthentication(reqJson,KEY);
        boolean authResult = true;
        if(authResult){
            map = externalMessageTempService.externalMessageTemp(reqJson);
        }else{
            map.put("resultCode","-1");
            map.put("resultDesc","接口鉴权失败");
        }

        log.info("【外部平台短信模板同步接口】返回数据：{}", map);
        return map;
    }

}
